package org.trade.user.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.trade.common.api.IUserApi;
import org.trade.common.constant.TradeEnums;
import org.trade.common.protocol.user.ChangeUserMoneyReq;
import org.trade.common.protocol.user.ChangeUserMoneyRes;
import org.trade.common.protocol.user.QueryUserReq;
import org.trade.common.protocol.user.QueryUserRes;
import org.trade.user.service.IUserService;

/*
 * 作为HTTP的接口调用
 */
@Controller
public class UserApiImpl implements IUserApi {
	@Autowired
	private IUserService userService;

	@RequestMapping(value = "/queryUser", method = RequestMethod.POST)
	@ResponseBody
	public QueryUserRes queryUser(@RequestBody QueryUserReq queryUserReq) {
		return userService.queryUser(queryUserReq);
	}

	@ResponseBody
	public ChangeUserMoneyRes changeUserMoney(@RequestBody ChangeUserMoneyReq changeUserMoneyReq) {
		ChangeUserMoneyRes changeUserMoneyRes = new ChangeUserMoneyRes();
		try {
			changeUserMoneyRes = this.userService.changeUserMoney(changeUserMoneyReq);
		} catch (Exception ex) {
			changeUserMoneyRes.setRetCode(TradeEnums.RetEnum.FAIL.getCode());
			changeUserMoneyRes.setRetInfo(ex.getMessage());
		}
		return changeUserMoneyRes;
	}

}
